﻿using System;
using System.Collections.Generic;
using Game.Model;
using UnityEngine;

/// <summary>
/// 游戏数据模型管理器组件
/// </summary>
public class ModelManager : MonoBehaviour
{
    /// <summary>
    /// 外部可访问单例
    /// </summary>
    public static ModelManager Instance { get; protected set; }

    /// <summary>
    /// 地图上所有的物件
    /// </summary>
    private List<IMapObject> _MapObjects;

    /// <summary>
    /// 需要刷新
    /// </summary>
    private bool _MapNeedRefresh;

    private void Start()
    {
        Instance = this;
    }

    /// <summary>
    /// 新游戏
    /// </summary>
    public void NewGame()
    {
        _MapObjects = new List<IMapObject>();
        {
            var char1 = new MapCharacter();
            var char2 = new MapCharacter();
            var char3 = new MapCharacter();
            char1.Name = "Akun";
            char2.Name = "Bkun";
            char3.Name = "Ckun";
            char1.MoveTo(new Vector2(100, 300), true);
            char2.MoveTo(new Vector2(50, 0), true);
            char3.MoveTo(new Vector2(-20, 100), true);
            AddMapObject(char1);
            AddMapObject(char2);
            AddMapObject(char3);
        }
    }

    /// <summary>
    /// 获取所有地图物件
    /// </summary>
    public List<IMapObject> GetMapObjects() => _MapObjects;
    
    /// <summary>
    /// 添加地图对象
    /// </summary>
    public void AddMapObject(IMapObject mapObject)
    {
        _MapObjects.Add(mapObject);
        _MapNeedRefresh = true;
    }

    /// <summary>
    /// 删除地图对象
    /// </summary>
    public void RemoveMapObject(IMapObject mapObject)
    {
        
    }

    /// <summary>
    /// 是否需要刷新
    /// </summary>
    public bool IsNeedRefresh => _MapNeedRefresh;

    /// <summary>
    /// 完成刷新
    /// </summary>
    public void CompleteRefresh()
    {
        _MapNeedRefresh = false;
    }
}